using System.Data;
using System.Data.SqlClient;
using Provausio.Common.Data;
using Provausio.Common.Objects;

namespace TrainingManagement.api.Models.Data.CRUD.TrainingRecord
{
    public class TrainingRecordCompletePendingDataSource : NonQuerySource<BusinessObjects.TrainingRecord>
    {
        public override bool Execute(BusinessObjects.TrainingRecord request)
        {
            const string completePending = "dbo.training_api_TrainingRecordCompletePending";
            var parameters = new SqlParameter[3];
            parameters[0] = new SqlParameter("@TrainingRecordID", SqlDbType.Int){Value = request.TrainingRecordId};
            parameters[1] = new SqlParameter("@InspectedBy", SqlDbType.Int){Value = request.InspectedBy};
            parameters[2] = new SqlParameter("@CompletedDate", SqlDbType.DateTime){ Value = request.CompletedDate};

            return SqlHelper.ExecuteNonQuery(
                ConnectionStrings.TrainingDb,
                CommandType.StoredProcedure,
                completePending,
                parameters) != 0;
        }
    }
}